home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-12-10 | 7.7 KB | 238 lines | [TEXT/ALFA] |
- alpha::mode Java 1.0 javaMenu {*.java *.j} javaMenu {
- addMenu javaMenu "•140"
- }
-
- newPref f elecColon {1} Java
- newPref f elecRBrace {1} Java
- newPref v leftFillColumn {3} Java
- newPref v prefixString {//} Java
- newPref f electricSemi {1} Java
- newPref f elecLBrace {1} Java
- newPref f wordWrap {0} Java
- newPref v funcExpr {^[^ \t\(#\r/@].*\(.*\)$} Java
- newPref v parseExpr {\b([_:\w]+)\s*\(} Java
- newPref v wordBreak {\w+} Java
- newPref v wordBreakPreface {\W} Java
- newPref f electricTab {0} Java
- newPref f autoMark 0 Java
- newPref v stringColor green Java
- newPref v commentColor red Java
- newPref v keywordColor blue Java
- newPref f includeMenu 1 Java
-
- regModeKeywords -e {//} -b {/*} {*/} -c $JavamodeVars(commentColor) -k $JavamodeVars(keywordColor) -s $JavamodeVars(stringColor) Java {
- abstract boolean break byte byvalue case catch char class const
- continue default do double else extends false final finally float for
- goto if implements import instanceof int interface long native new
- null package private protected public return short static super switch
- synchronized this throw throws transient true try void while future
- generic inner outer operator rest var volatile
- }
-
- proc javaMenu {} {}
-
- ##
- # -------------------------------------------------------------------------
- #
- # "menu::buildjavaMenu" --
- #
- # Use a build proc so we can add things on the fly.
- # -------------------------------------------------------------------------
- ##
- proc menu::buildjavaMenu {} {
- global javaMenu
- set ma {
- "/S<U<OswitchToCompiler"
- "(-"
- "/K<U<OcompileFile"
- "(-"
- "/V<U<OviewApplet"
- }
- return [list build $ma Java::MenuProc "" $javaMenu]
- }
- menu::buildProc javaMenu menu::buildjavaMenu
-
- # If this package exists, add the headers menu
- if [alpha::package exists -extension modeSearchPaths] {
- menu::buildProc javaHeaders {mode::rebuildSearchPathMenu javaHeaders}
- menu::insert javaMenu submenu end javaHeaders
- }
-
- menu::buildSome javaMenu
-
- proc Java::MenuProc {menu item} {
- eval Java::$item
- }
-
- # Launches Java Compiler
- proc Java::switchToCompiler {} {
- global javacompilerSig
- app::launchAnyOfThese Javc javacompilerSig "Please locate the Java compiler:"
- switchTo '$javacompilerSig'
- }
-
- # Sends the window to the compiler.
- proc Java::compileFile {} {
- global javacompilerSig
- set path [stripNameCount [win::Current]]
-
- if {[winDirty]} {
- case [askyesno -c "Save '[file tail $path]'?"] in {
- "yes" {save}
- "no" {
- if {![file exists $path]} {alertnote "Can't send window to compiler."; return}
- }
- "cancel" {return}
- }
- }
- # Get path again, in case it was Untitled before.
- set path [stripNameCount [win::Current]]
- app::launchAnyOfThese Javc javacompilerSig "Please locate the Java compiler:"
- sendOpenEvent -n '$javacompilerSig' $path
- switchTo '$javacompilerSig'
- }
-
- # Opens a HTML file corresponding to a java file in the Applet Viewer.
- # If there is a file some_applet.html in the same folder as some_applet.java
- # it is sent. Otherwise the user is asked to select a HTML file.
- # This file is remembered throughout this session with Alpha.
- proc Java::viewApplet {} {
- global javaAppletFile javaviewerSig
- set name [stripNameCount [win::Current]]
- set dir [file dirname $name]
- set root [file rootname [file tail $name]]
- set path "$dir:$root.html"
- if {[info exists javaAppletFile($name)] && [file exists $javaAppletFile($name)]} {
- set path $javaAppletFile($name)
- } elseif {![file exists $path]} {
- set path [getfile "Please locate HTML file for applet."]
- set javaAppletFile($name) $path
- }
- app::launchAnyOfThese [list AppV WARZ] javaviewerSig "Please locate the Applet viewer:"
- sendOpenEvent noReply '$javaviewerSig' $path
- switchTo '$javaviewerSig'
- }
-
- proc Java::MarkFile {} {
- Java::MarkFile2 1
- }
-
- proc Java::parseFuncs {} {
- Java::MarkFile2 0
- }
-
-
- # My version of Java::MarkFile. First revision, April 1996.
- # Jim Menard, jimm@io.com
- proc Java::MarkFile2 {marking} {
- # Sorry, but globals are a lot easier than using "upvar" in subroutines
- global markArray
- global classStartPositions
- global classNames
-
- catch { unset markArray }
-
- # Look for class definitions first
- set markExpr {^[ \t]*([A-Za-z_][A-Za-z0-9_]*[ \t]+)*class[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t\r]([A-Za-z_][A-Za-z0-9_.]*[ \t]+)*\{}
- set wordExpr {class[ \t]+([A-Za-z_][A-Za-z0-9_]*)}
- set commands {
- set markArray([concat $word "class"]) $markPos
- # Remember mark position and name separately so we can call
- # Java::getClassFromPos() later.
- lappend classStartPositions $markPos
- lappend classNames $word
- }
- Java::searchAndDestroy $markExpr $wordExpr $commands 0
-
- # The following regular expression is overly restrictive. After the open
- # paren, I disallow semicolons. That avoids finding lines like
- # throw new FooException(arg);
- # which is good, but unfortunately also avoids finding lines like
- # public int foo(arg) // comment with semi;
- #
- # It doesn't find constructors without a "public", "private", or other phrase
- # before the method name since it requires at least one word before the
- # method name. They are special-cased below. I did that so function calls,
- # "if" statements, and the like wouldn't be found.
- set markExpr {^[ \t]*([A-Za-z_][A-Za-z0-9_]*(\[\])*[ \t]+)+[A-Za-z_][A-Za-z0-9_]*[ \t\r]*\([^;]+$}
- set wordExpr {([A-Za-z_][A-Za-z0-9_]*)[ \t]*\(}
- set commands {
- if {$className == $word} {
- set markArray([concat $className "constructor"]) $markPos
- } else {
- set markArray(${className}::$word) $markPos
- }
- }
- Java::searchAndDestroy $markExpr $wordExpr $commands 1
-
- # One more time; let's go back for constructors with no modifiers.
- set markExpr {^[ \t]*[A-Za-z][A-Za-z0-9_]*[ \t\r]*\([^;]+$}
- set wordExpr {([A-Za-z][A-Za-z0-9_]*)[ \t]*\(}
- set commands {
- if {$className == $word} {
- set markArray([concat $className "constructor"]) [lineStart [expr $start - 1]]
- }
- }
- Java::searchAndDestroy $markExpr $wordExpr $commands 1
-
- if {[info exists markArray]} {
- foreach f [lsort -ignore [array names markArray]] {
- set next [nextLineStart $markArray($f)]
-
- if {[regexp {.*(::if)$} $f] == 0} {
- if {[string length $f] > 35} { set f "[string range $f 0 31]..." }
- if {$marking} {
- setNamedMark "${f}" "$markArray($f)" $next $next
- } else {
- lappend parse $f $next
- }
- }
- }
- }
- if {!$marking} {return $parse}
- }
-
- # Start at top of file and find text that matches markExpr. Clean it up and
- # use wordExpr to find the word we want. Execute commands.
- proc Java::searchAndDestroy {markExpr wordExpr commands needClassName} {
- global markArray
- global classStartPositions
- global classNames
-
- set pos 0
- while {![catch {search -s -f 1 -r 1 -m 0 -i 0 "$markExpr" $pos} res]} {
- set start [lindex $res 0]
- set end [expr [lindex $res 1] + 1]
- set thistext [getText $start $end]
- if {$needClassName} {
- set className [Java::getClassFromPos $start $classStartPositions $classNames]
- }
- # regexp doesn't like carriage returns or tabs
- regsub -all "\r" $thistext " " thistext
- regsub -all "\t" $thistext " " thistext
- # If the open paren was the last character on the line,
- # the selected text included the last carriage return as well.
- # Trim this off now that it is changed into a space.
- set thistext [string trimright $thistext]
- if {[regexp $wordExpr $thistext dummy word]} {
- set markPos [lineStart [expr $start - 1]]
- eval $commands
- }
- set pos $end
- }
- }
-
- # Given a file position, find the class definition in which it resides.
- # There's got to be an easier way than passing two separate lists. I tried fooling
- # around with markArray(), but don't know Tcl well enough to use it instead.
- proc Java::getClassFromPos {pos classStartPositions classNames} {
- set nClasses [llength $classStartPositions]
- for {set i [expr $nClasses - 1]} {$i >= 0} {set i [expr $i - 1]} {
- if {[lindex $classStartPositions $i] <= $pos} {
- return [lindex $classNames $i]
- }
- }
- return ""
- }
-
-